package com.xbongbong.sso.model.impl;

import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.sso.domain.dao.OauthParamDao;
import com.xbongbong.sso.domain.entity.OauthParamEntity;
import com.xbongbong.sso.model.OauthParamModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author bomfish
 */
@Service("oauthParamModel")
public class OauthParamModelImpl implements OauthParamModel {

    private static final Logger LOG = LoggerFactory.getLogger(OauthParamModelImpl.class);

    @Resource
    private OauthParamDao oauthParamDao;

    @Override
    public Long insert(OauthParamEntity entity) {
        return oauthParamDao.insert(entity);
    }

    @Override
    public void insertBatch(List<OauthParamEntity> list) {
        oauthParamDao.insertBatch(list);
    }

    @Override
    public List<OauthParamEntity> findEntities(Map<String, Object> param) {
        return oauthParamDao.findEntities(param);
    }

    @Override
    public Integer getEntityCount(Map<String, Object> param) {
        return oauthParamDao.getEntitiesCount(param);
    }

    @Override
    public void update(OauthParamEntity entity) {
        oauthParamDao.update(entity);
    }

    @Override
    public OauthParamEntity getByKey(Long key, String corpid) {
        return oauthParamDao.getByKey(key, corpid);
    }

    @Override
    public Long delete(Long key, String corpid) {
        return oauthParamDao.deleteByKey(key, corpid);
    }

    @Override
    public List<OauthParamEntity> getOauthParams(String corpid, Long stepId, Integer stageType, Integer enable) {
        Map<String, Object> param = new HashMap<>();
        param.put("corpid", corpid);
        param.put("stepId", stepId);
        param.put("stageType", stageType);
        param.put("enable", enable);
        param.put("del", DelEnum.NORMAL.getDel());
        LOG.info("param:" + param);
        return findEntities(param);
    }
}
